<template>
	<view class="newIndex">
		<navBar v-if="loginStatus"><view class="iconfont iconTop" slot="center" @click="toOutLogin">{{icon}}</view></navBar>
		<!-- <nav-bars v-if="loginStatus">
			<view class="iconfont" slot="center" @click="toOutLogin">&#xe634;</view>
		</nav-bars> -->
		<view class="center">
			<view class="imgBox">
				<image :src="`${baseImg}/static/ryzLogo/logo-2.png`" mode=""></image>
				合作管理端
			</view>
			<view class="btn">
				<view class="item" @click="openMiniUser">融易装首页</view>
				<view class="item item1" @click="toPartner">进入合作商管理</view>
			</view>
		</view>
		
		<u-popup v-model="show" mode="bottom" safe-area-inset-bottom border-radius="20">
			<view class="popupBox">
				<view class="btn" @click="changeStore">
					<text class="iconfont">&#xe61a;</text>
					<text>切换店铺</text>
				</view>
				<view class="btn active" @click="outLoginFn">
					<text class="iconfont">&#xe634;</text>
					<text>退出登录</text>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
import Https from '@/service/verification.js';
import service_enter from '@/service/enter.js';
export default {
	data() {
		return {
			baseImg: this.$static,
			enterType: null,
			enterStatus: null,
			enterReason: '',
			roleStatus: '',
			loginStatus: false,
			// btnRootStatus:true, //没有权限（权限接口返回-9）
			// btnRootMsg:'',//没有权限时的信息
			show:false,
			count:1,
			icon:'\ue669'
		};
	},
	onShow() {
		this.count = this.$store.state.index.storeCount
		this.icon = this.count>1?'\ue669':'\ue634'
		let token = this.$store.state.index.token;
		if (token) {
			this.loginStatus = true;
			this.getEnterStatus();
			this.getAllRoot();
		}
	},
	methods: {
		// 获取入驻状态
		getEnterStatus() {
			let user_id = this.$store.state.index.userId;
			service_enter.getEnterStatus({ user_id }).then(res => {
				// console.log(res, '入驻状态');
				if (res.code == 1) {
					this.enterStatus = res.data.status;
					this.enterType = res.data.type;
					this.enterReason = res.data.reason;
					this.roleStatus = res.data.role ? res.data.role : '';
				}
			});
		},
		// 所有权限
		getAllRoot() {
			let params = {
				user_id: this.$store.state.index.userId,
				page: 1,
				pagesize: 10
			};
			this.$api.allRoot(params).then(res => {
				// console.log(res, '所有权限');
				if (res.code == 1) {
					let page = res.data;
					this.$store.commit('index/SET_page', page);
				}else if(res.code==-9){
					this.btnRootStatus = false
					this.btnRootMsg = res.msg
				}
			});
		},
		// 切换店铺
		changeStore(){
			let mobile = this.$store.state.index.userMobile
			uni.navigateTo({
				url:'/pages/enter/selectStore/index?mobile='+ mobile
			})
		},
		// 顶部退出登录按钮
		toOutLogin(){
			// console.log(this.count,'店铺数量')
			if(this.count*1>1){
				this.show = true
			}else{
				this.outLoginFn()
			}
		},
		// 多店弹出退出登录按钮
		outLoginFn() {
			uni.showModal({
				title: '提示',
				content: '确定退出登录?',
				success: res => {
					if (res.confirm) {
						let token = '';
						let isBindMobile = '';
						let userMobile = '';
						let userId = '';
						let role = '';
						let sid = '';
						let page = '';
						let count = '';
						let identityType = '';
						this.$store.commit('index/SET_token', token);
						this.$store.commit('index/SET_role', role);
						this.$store.commit('index/SET_sid', sid);
						this.$store.commit('index/SET_tokenTime', Date.now());
						this.$store.commit('index/SET_isBindMobile', isBindMobile);
						this.$store.commit('index/SET_userMobile', userMobile);
						this.$store.commit('index/SET_userId', userId);
						this.$store.commit('index/SET_page', page);
						this.$store.commit('index/SET_identityType', identityType);
						this.$store.commit('index/SET_storeCount', count);
						uni.clearStorage();
						uni.reLaunch({
							url: '/pages/mall/newIndex/newIndex'
						});
					} else {
					}
				}
			});
		},
		// 进入合作商
		toPartner() {
			let token = this.$store.state.index.token;
			if (token) {
				if (this.enterType == 0) {
					uni.navigateTo({
						url: '/pages/enter/index/index'
					});
				} else {
					if (this.enterStatus == 0) {
						// console.log('申请中');
						uni.navigateTo({
							url: '/pages/enter/index/audit'
						});
					} else if (this.enterStatus == 1) {
						// console.log('通过了');

						// 是否创客
						let role = this.$store.state.index.role;
						//本地是否缓存角色信息，与roleStatus入驻是否有角色状态，如果没有缓存且入驻有角色状态，提示登录
						// console.log(role, '角色');
						// console.log(this.roleStatus,'--')
						if (!role && this.roleStatus != '') {
							uni.showModal({
								content: '申请通过，请重新登录！',
								success: res => {
									if (res.confirm) {
										uni.reLaunch({
											url: '/pages_login/pages/login/login/index'
										});
									}
								}
							});
						} else {
							// this.getAccountInfo();
							let router = this.$store.state.index.page?this.$store.state.index.page.ability:[]
							// console.log(router,'、、、、、')
							if(router.findIndex(item=>item.route == 'adminIndex')!=-1){ //总后台
								uni.navigateTo({
									url:'/pages_admin/home/home'
								})
							}else if(router.findIndex(item=>item.route == 'shopIndex')!=-1){ //商家
								uni.navigateTo({
									url:'/pagesFour/home/home'
								})
							}else if(router.findIndex(item=>item.route == 'designerIndex')!=-1){ //设计师
								uni.navigateTo({
									url:'/pageTwo/home/home'
								})
							}else if(router.findIndex(item=>item.route == 'builderIndex')!=-1){ //施工队
								uni.navigateTo({
									url:'/pagesOne/constr/home/home'
								})
							}else if(router.findIndex(item=>item.route == 'decorationIndex')!=-1){ //装修公司
								uni.navigateTo({
									url:'/pages_decoration/home/home'
								})
							}else if(router.findIndex(item=>item.route == 'promoterIndex')!=-1){
								// if(uni.getUserProfile){
								// 	uni.getUserProfile({
								// 		desc:'Wexin',  // 这个参数是必须的
								// 		success:res=>{
								// 			console.log(res)
								// 			if(res.errMsg == 'getUserProfile:ok'){
								// 				uni.setStorageSync('userInfo',res.userInfo)
												uni.navigateTo({
													url:'/pagesOne/distri/index/index'
												})
								// 			}
								// 		},
								// 		fail:err=>{
								// 			console.log(err)
								// 		}
								// 	})
								// }
							}else{
								uni.navigateTo({
									url:'/pages/enter/index/index'
								})
							}
						}
					} else if (this.enterStatus == 2) {
						// console.log('没通过');
						uni.navigateTo({ url: '/pages/enter/index/fail?reason=' + this.enterReason });
					}
				}
			} else {
				uni.showModal({
					content: '未登录，请先登录！',
					success: res => {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages_login/pages/login/login/index'
							});
						}
					}
				});
			}
		},
		// 查询云商通账户信息
		// getAccountInfo() {
		// 	var that = this;
		// 	let params = {};
		// 	Https.GetAccountMes(params).then(res => {
		// 		if (res.code == 1) {
		// 			console.log(res.data);
		// 			var data = res.data;

		// 			if (data.is_realname == 0) {
		// 				uni.showModal({
		// 					title: '提示',
		// 					content: '暂时还没实名验证,是否实名验证?',
		// 					confirmText: '确定',
		// 					success: function(res) {
		// 						if (res.confirm) {
		// 							uni.navigateTo({
		// 								url: '/pages_Verification/verification/select/list'
		// 							});
		// 						}
		// 					}
		// 				});
		// 				return;
		// 			}
		// 			if (data.is_realname == 1) {
		// 				if (data.is_phone == 0) {
		// 					uni.showModal({
		// 						title: '提示',
		// 						content: '暂时还没绑定手机号,是否绑定?',
		// 						confirmText: '确定',
		// 						success: function(res) {
		// 							if (res.confirm) {
		// 								uni.navigateTo({
		// 									url: '/pages_Verification/verification/bindPhone/BindPhone'
		// 								});
		// 							}
		// 						}
		// 					});
		// 				} else if (data.is_sign == 0) {
		// 					uni.showModal({
		// 						title: '提示',
		// 						content: '需要完善支付信息,是否继续?',
		// 						confirmText: '确定',
		// 						success: function(res) {
		// 							if (res.confirm) {
		// 								uni.navigateToMiniProgram({
		// 									appId: 'wxc46c6d2eed27ca0a', //通商云平台账户小程序appId
		// 									path: 'pages/merchantAddress/merchantAddress',
		// 									extraData: {
		// 										// 测试环境地址：url=https://test.allinpay.com/yungateway/member/signContract.html?
		// 										// 生产环境地址：url=https://fintech.allinpay.com/yungateway/member/signContract.html?
		// 										targetUrl: 'https://test.allinpay.com/yungateway/member/signContract.html?' + data.signContract.data.param //商户拼接的请求报文
		// 									},
		// 									envVersion: 'release', //develop 开发版  trial 体验版  release 正式版
		// 									success(res) {
		// 										// 打开成功
		// 										console.log(res);
		// 									}
		// 								});
		// 							}
		// 						}
		// 					});
		// 					// let url = encodeURIComponent('https://test.allinpay.com/yungateway/member/signContract.html?' + data.signContract.data.param);
		// 					// uni.navigateTo({
		// 					// 	url: '/pagesOne/verification/webview?url=' + url
		// 					// });
		// 				} else if (data.is_phone == 1 && data.is_sign == 1) {
		// 					let router = this.$store.state.index.page ? this.$store.state.index.page.ability : [];
		// 					// console.log(router, '、、、、、');
		// 					if (router.findIndex(item => item.route == 'adminIndex') != -1) {
		// 						//总后台
		// 						uni.navigateTo({
		// 							url: '/pages_admin/home/home'
		// 						});
		// 					} else if (router.findIndex(item => item.route == 'shopIndex') != -1) {
		// 						//商家
		// 						uni.navigateTo({
		// 							url: '/pagesFour/home/home'
		// 						});
		// 					} else if (router.findIndex(item => item.route == 'designerIndex') != -1) {
		// 						//设计师
		// 						uni.navigateTo({
		// 							url: '/pageTwo/home/home'
		// 						});
		// 					} else if (router.findIndex(item => item.route == 'builderIndex') != -1) {
		// 						//施工队
		// 						uni.navigateTo({
		// 							url: '/pagesOne/constr/home/home'
		// 						});
		// 					} else if (router.findIndex(item => item.route == 'decorationIndex') != -1) {
		// 						//装修公司
		// 						uni.navigateTo({
		// 							url: '/pages_decoration/home/home'
		// 						});
		// 					} else if (router.findIndex(item => item.route == 'promoterIndex') != -1) {
		// 						uni.navigateTo({
		// 							url: '/pagesOne/distri/index/index'
		// 						});
		// 					} else {
		// 						uni.navigateTo({
		// 							url: '/pages/enter/index/index'
		// 						});
		// 					}
		// 					// if (data.member_type == 3) {
		// 					// 	// 个人
		// 					// 	uni.navigateTo({
		// 					// 		url: '/pages_Verification/verification/bankCard/bankCardList?memberType=3'
		// 					// 	});
		// 					// } else if (data.member_type == 2) {
		// 					// 	// 企业
		// 					// 	uni.navigateTo({
		// 					// 		url: '/pages_Verification/verification/bankCard/bankCardList?memberType=2'
		// 					// 	});
		// 					// }
		// 				}
		// 				return;
		// 			}
		// 			if (data.is_realname == 2) {
		// 				if (data.member_type == 3) {
		// 					// 个人
		// 					uni.navigateTo({
		// 						url: '/pages_Verification/verification/status/status?isPersonal=true&status=0&isIndex=true'
		// 					});
		// 				} else if (data.member_type == 2) {
		// 					// 企业
		// 					uni.navigateTo({
		// 						url: '/pages_Verification/verification/status/status?isPersonal=false&status=0&isIndex=true'
		// 					});
		// 				}
		// 				return;
		// 			}
		// 		} else {
		// 			uni.showToast({
		// 				title: res.msg,
		// 				icon: 'none'
		// 			});
		// 		}
		// 	});
		// },
		// 进入用户端小程序
		openMiniUser() {
			uni.showModal({
				content: '即将跳转小程序',
				success(res) {
					if (res.confirm) {
						uni.navigateToMiniProgram({
							appId: 'wx66230223cee807f1', // 其他小程序APPID
							path: '/pages/home/index/index', //user_id=${user_id}//其他小程序地址
							success: res => {
								// 打开成功
								console.log('打开成功', res);
							},
							fail: err => {
								console.log(err);
							}
						});
					}
				}
			});
		}
	}
};
</script>

<style lang="scss">
@import 'iconfont.css';
page {
	width: 100%;
	height: 100%;
}
.newIndex {
	width: 100%;
	height: 100%;
	background-color: #fff;
	.iconTop {
		border-radius: 50%;
		width: 100%;
		text-align: left;
		// height: 80rpx;
		color: #bbb;
		padding-left: 30rpx;
		font: 400 40rpx/60rpx PingFang SC;
	}
	.center {
		display: flex;
		flex-direction: column;
		align-items: center;
		position: absolute;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		margin: auto;
		width: 100%;
		.imgBox {
			text-align: center;
			width: 100%;
			image {
				width: 85%;
				height: 600rpx;
				margin: 0 auto;
			}
			font: 600 50rpx/0rpx PingFang SC;
			color: #333;
		}
		.btn {
			width: 100%;
			padding: 0 100rpx;
			margin-top: 260rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.item {
				padding: 0 40rpx;
				font: 500 30rpx/60rpx PingFang SC;
				border: 2rpx solid #505050;
				border-radius: 32rpx;
				color: #333;
			}
			.item1 {
				background-color: #dba954;
				color: #fff;
				border-color: #dba954;
			}
		}
	}
	.popupBox{
		// width: 502rpx;
		padding: 30rpx;
		display: inline-flex;
		// flex-direction: column;
		.btn{
			padding:20rpx 60rpx;
			border: 2rpx solid #dba954;
			background-color: #dba954;
			border-radius: 60rpx;
			font: 500 30rpx/60rpx PingFang SC;
			color: #fff;
			display: flex;
			align-items: center;
			margin: 30rpx;
			.iconfont{
				margin-right: 20rpx;
			}
			text{
				flex-shrink: 0;
			}
		}
		.active{
			border-color: #333;
			background-color: #fff;
			color: #333;
		}
	}
}
</style>
